package com.hpu.callback;

import android.os.Handler;
import android.os.Message;

import com.hpu.constants.HttpConstants;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * 实现了周次校准业务类的回调接口
 * @author Administrator
 *
 */
public class WeekCallback implements Callback {

	private Handler handler;

	public WeekCallback(Handler handler) {
		this.handler = handler;
	}

	@Override
	public void onFailure(Call arg0, IOException arg1) {
		handler.sendEmptyMessage(HttpConstants.QUERY_WEEK_ERROR);
	}

	@Override
	public void onResponse(Call arg0, Response arg1) throws IOException {
		String result = arg1.body().string();
		
		if(result!=null&&result.equals("404")) handler.sendEmptyMessage(HttpConstants.VPN_TOOLONG);
		else{
			Message message = new Message();
			message.what = HttpConstants.QUERY_WEEK_SUCCESS;
			message.obj = result;
			handler.sendMessage(message);
		}
		
	}

}
